package com.example.demo;

import com.example.demo.Repository.UserRepository;
import com.example.demo.entity.User;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
}
    @Bean
    public CommandLineRunner dataLoader(UserRepository userRepo) {
        return new CommandLineRunner() {

            @Override
            public void run(String... args) throws Exception {

                BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
                User user1 = new User("zhangsan", encoder.encode("8888"));
                User user2 = new User("lisi", encoder.encode("8888"));
                userRepo.save(user1);
                userRepo.save(user2);
            }
        };
    }
}